package problema032;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class PandigitalProducts {
	
	static Set<Integer> act = new HashSet<Integer>();
	static Set<Integer> res = new HashSet<Integer>();

	public static void main(String[] args){
		System.out.println(sumaPanProd());
	}
	
	public static long sumaPanProd(){
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 2000; j++){
				act.clear();
				if(pasar(i) && pasar(j) && pasar(i*j)){
					if(!res.contains(i*j) && esPan()){
						res.add(i*j);
					}
				}
			}
		}
		return resultado();
	}
	
	public static boolean esPan(){
		if(act.contains(0)) return false;
		for(int i = 1; i < 10; i++){
			if(!act.contains(i))return false;
		}
		return true;
	}
	
	public static long resultado(){
		Iterator<Integer> it = res.iterator();
		long res = 0;
		while(it.hasNext()){
			res += (long) it.next();
		}
		return res;
	}
	
	public static boolean pasar(int i){
		while(i > 0){
			if(act.contains(i%10))return false;
			act.add(i%10);
			i = i / 10;
		}
		return true;
	}
	
	
}
